from Sudoku.SudokuSolver import SudokuSolver


class TwoArray:

    @classmethod
    def reshape_to_2d_grid(self, digits, rows=9, cols=9):
        """
        将一维数独列表整理为 9x9 的二维表格，按列填充。
        :param digits: 一维数独列表
        :param rows: 行数（默认为 9）
        :param cols: 列数（默认为 9）
        :return: 9x9 的二维表格
        """
        if len(digits) != rows * cols:
            raise ValueError("输入列表的长度必须为 81（9x9）。")

        # 初始化一个 9x9 的二维表格
        grid = [[0 for _ in range(cols)] for _ in range(rows)]

        # 按列填充
        index = 0
        for col in range(cols):
            for row in range(rows):
                grid[row][col] = digits[index]
                index += 1

        return grid


if __name__ == '__main__':
    """
    接收一个一维列表，按列填充，转为二维列表
    """
    lists = [0, 0, 7, 0, 2, 3, 0, 4, 8, 0, 4, 2, 5, 0, 8, 0, 3, 0, 3, 9, 8, 1, 4, 6, 5, 7, 0, 2, 7, 9, 6, 8, 1, 3,
             5, 0, 1, 5, 0, 7, 3, 4, 0, 8, 9, 0, 3, 4, 2, 9, 5, 1, 6, 7, 0, 2, 5, 4, 6, 7, 8, 1, 3, 0, 6, 0, 8, 0,
             2, 4, 9, 0, 4, 8, 0, 3, 5, 0, 7, 0, 0]
    sudoku_grid = TwoArray.reshape_to_2d_grid(lists)
    for row in sudoku_grid:
        print(row)
